# README.md generator

import os


TEMPLATE = """Privacy tools written in Python.

## List
|Folder|Description|
|------|-----------|
%(rows)s
"""


def build_table(rows: list[str]):
    return TEMPLATE % {
        "rows": "\n".join(rows),
    }


def build_row(folder: str, description: str) -> str:
    return "|%s|%s|" % (folder, description.strip())


def main():
    rows = []

    for root, dirs, files in os.walk("."):
        if root == ".":
            continue

        if "README.md" not in files:
            continue

        with open(os.path.join(root, "README.md"), encoding="utf-8") as file:
            readme = file.readlines()

        rows.append(build_row(os.path.basename(root), readme[0]))

    with open("README.md", "w") as file:
        file.write(build_table(rows))


if __name__ == "__main__":
    main()
